/// <summary>
// DBLinq.MySqlProviders - .NET Providers for MySql using the framework DBLinq under MIT license, author Jiri George Moudry
// http://linq.to/db
// and the CodeFx.MySqlProviders under GNU licence, author Laurent Morisseau
// http://www.codeplex.com/CodeFxMySqlProvider
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
//
// Laurent Morisseau
/// </summary>
/// <author><a href="mailto:laurent.morisseau@gmail.com">Laurent Morisseau</a></author>

namespace DBLinq.MySqlProviders
{
	using System.Linq;

	internal static partial class AspNetUsersInRolesDTO
    {

        internal static void Insert(AspNetUsersInRole user)
		{
			using ( aspnetcontext context = new aspnetcontext ( ConnectionString.Current.CurrentString ) )
			{
				context.AspNetUsersInRoles.Add ( user );
				context.SubmitChanges ();
			}
		}


		internal static void DeleteByFk_UserId( uint UserID )
		{
			using ( aspnetcontext context = new aspnetcontext ( ConnectionString.Current.CurrentString ) )
			{
                AspNetUsersInRole member = context.AspNetUsersInRoles.Where<AspNetUsersInRole>(p => p.UserId == UserID).ToList().First();
				context.AspNetUsersInRoles.Remove ( member );
				context.SubmitChanges ();
			}

		}

		internal static void DeleteByFk_RoleId ( uint RoleID )
		{
			using ( aspnetcontext context = new aspnetcontext ( ConnectionString.Current.CurrentString ) )
			{
                AspNetUsersInRole member = context.AspNetUsersInRoles.Where(p => p.RoleId == RoleID).ToList().First();
                context.AspNetUsersInRoles.Remove ( member );
				context.SubmitChanges ();
			}
		}


		internal static void DeleteByFk_UserId_RoleId( uint UserID, uint RoleID )
		{
			using ( aspnetcontext context = new aspnetcontext ( ConnectionString.Current.CurrentString ) )
			{
                AspNetUsersInRole member = context.AspNetUsersInRoles.Where<AspNetUsersInRole>(p => p.RoleId == RoleID && p.UserId == UserID).ToList().First<AspNetUsersInRole>();
				context.AspNetUsersInRoles.Remove ( member );
				context.SubmitChanges ();
			}
		}

        internal static bool Exist(uint _RoleId)
        {

		  using ( aspnetcontext context = new aspnetcontext ( ConnectionString.Current.CurrentString ) )
		  {
			  return context.AspNetUsersInRoles.Where<AspNetUsersInRole> ( p => p.RoleId == _RoleId ).ToList().Count>0;
		  }
        }


	  internal static bool Exist( uint _UserId, uint _RoleId )
	  {

		  using ( aspnetcontext context = new aspnetcontext ( ConnectionString.Current.CurrentString ) )
		  {
			  return context.AspNetUsersInRoles.Where<AspNetUsersInRole> ( p => p.RoleId == _RoleId && p.UserId == _UserId ).ToList().Count>0;
		  }
	  }
    }
}